// executor:接收的执行器函数
function Promise(executor){
	// 设置初始状态
	this.state = "pending";
	// 设置初始状态值
	this.result = undefined;
	function _resolve(v){
		// 判断状态是否已经被更改
		if(this.state !== "pending") return;
		this.state = "fulfilled";
		this.result = v;
	}
	function _reject(v){
		if(this.state !== "pending") return;
		this.state = "rejected";
		this.result = v;
	}
	try{
		// 调用执行器函数，并传递两个参数（类型为函数）
		executor(_resolve.bind(this),_reject.bind(this));
	}catch (err){
		_reject.call(this,err);
	}
}
Object.assign(Promise.prototype,{
	// onResolved:成功回调
	// onRejected:失败回调
	then(onResolved,onRejected){
		// 状态为fulfilled调用onResolved
		// 状态为rejected调用onRejected
		if(this.state === "fulfilled"){
			onResolved(this.result);
		}else if(this.state === "rejected"){
			onRejected(this.result);
		}
	}
})